using System;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Xml;
using System.Reflection;

using Services;

using Utilities.Menu.UIElements;
using Services.Menu;
using Utilities.Menu;
using System.Collections.ObjectModel;
using EnhancedTimer.Resources;
using Microsoft.Phone.Shell;

namespace EnhancedTimer
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        public static int DEFAULT_SCR_WIDTH = 800;
        public static int DEFAULT_SCR_HEIGHT = 480;

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        //Microsoft.Devices.VibrateController.Default.Start(new TimeSpan(0, 0, 1));
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            StateManager StateManager = new StateManager(this, graphics);
            this.Services.AddService(typeof(AStateManager), StateManager);

            Strings.Culture = CultureInfo.CurrentCulture;
            Selector.Culture = CultureInfo.CurrentCulture;
            graphics.SupportedOrientations = DisplayOrientation.Portrait;
            graphics.PreferredBackBufferWidth = 480;
            graphics.PreferredBackBufferHeight = 800;
            StateManager.SelectIntroScreen();
            StateManager.LoadAlertSounds();
            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);
            

            graphics.SynchronizeWithVerticalRetrace = true;
            
            //StateManager.SelectMainMenu();
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        protected override void Dispose(bool disposing)
        {
            this.Services.RemoveService(typeof(SpriteBatch));
            base.Dispose(disposing);
        }

        internal void Draw()
        {
            this.Draw(new GameTime(TimeSpan.Zero, TimeSpan.Zero));
        }
                

        protected override void EndRun()
        {
            Microsoft.Devices.VibrateController.Default.Stop();
            base.EndRun();
        }
    }
}
